package com.bytecodes.eaulas.conexion;

import java.util.*;
import java.util.List;
import java.util.ArrayList;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.bytecodes.eaulas.comun.servicios.TDSLanguageUtils;
import com.bytecodes.eaulas.comun.servicios.EAulasServiciosInterface;
import com.bytecodes.eaulas.beans.*;


public class PantallaMostrar extends JFrame {

        private JTextField txt1 = new JTextField();
	private JTextField txt2 = new JTextField();
	private JTextField txt3 = new JTextField();
	private JTextField txt4 = new JTextField();
	private JTextField txt5 = new JTextField();
        private EAulasServiciosInterface remoto;    
        private Integer ifil;     
	List<ReservaRecurso> listaRecursos = null;        
        
	/**************************************************************************
	*	Constructor de la classe
	*	@param Frame La finestra propiet�ria
	*	@param GestorConnexio La connexio amb la BD
	*/
	public PantallaMostrar (EAulasServiciosInterface rem, Integer Bookings, String missatge) {
		// Creem la finestra modal
                
                remoto = rem;
		// Els components
		JPanel pDades = new JPanel();
		pDades.setLayout(null);
		pDades.setBounds( new Rectangle(10,10,550,300) );
		pDades.setBorder( BorderFactory.createTitledBorder("") );
                pDades.setBackground(Color.WHITE);  
                
                //
		JPanel pDades1 = new JPanel();
		pDades1.setLayout(null);
		pDades1.setBounds( new Rectangle(10,230,500,60) );                
		pDades1.setBorder( BorderFactory.createTitledBorder(TDSLanguageUtils.getMessage("mostrar.titulo1")));
                
                String tituloventana = (TDSLanguageUtils.getMessage("mostrar.titulo")); 
		setTitle(tituloventana);
                                
		JLabel lbl1 = new JLabel(TDSLanguageUtils.getMessage("mostrar.lbl1"));
		JLabel lbl2 = new JLabel(TDSLanguageUtils.getMessage("mostrar.lbl2"));
		JLabel lbl3 = new JLabel(TDSLanguageUtils.getMessage("mostrar.lbl3"));
		JLabel lbl4 = new JLabel(TDSLanguageUtils.getMessage("mostrar.lbl4"));
                
                if (!missatge.equals("")) {
                    
		JPanel pMissatge = new JPanel();
		pMissatge.setLayout(null);
		pMissatge.setBounds( new Rectangle(20,100,360,70) );
		pMissatge.setBorder( BorderFactory.createTitledBorder(TDSLanguageUtils.getMessage("mostrar.lbl8")) );
                pMissatge.setBackground(Color.WHITE);  
                
                pDades.add(pMissatge,null);
                
                txt5.setText(missatge);                
		txt5.setBounds(new Rectangle(15,35,300,20));
                txt5.setEnabled(false);
                pMissatge.add(txt5,null);
                }
                
		lbl1.setBounds(new Rectangle(20,20,85,20));
                txt1.setText(Bookings.toString());                
		txt1.setBounds(new Rectangle(80,20,90,20));
                
                txt1.setEnabled(false);
                txt2.setEnabled(false);
                txt3.setEnabled(false);
                txt4.setEnabled(false);
		pDades.add(lbl1,null);
		pDades.add(txt1,null);

                ifil = 50;
		lbl2.setBounds(new Rectangle(20,ifil,85,20));
		txt2.setBounds(new Rectangle(80,ifil,300,20));
		lbl3.setBounds(new Rectangle(390,ifil,85,20));                
		txt3.setBounds(new Rectangle(470,ifil,70,20));
                ifil = ifil + 30;
		lbl4.setBounds(new Rectangle(390,ifil,85,20));                
		txt4.setBounds(new Rectangle(470,ifil,70,20));
                
		pDades.add(lbl2,null);
		pDades.add(lbl3,null);
		pDades.add(lbl4,null);
		pDades.add(txt2,null);
		pDades.add(txt3,null);
		pDades.add(txt4,null);

                LeeRecursos(Bookings);
                
		JButton btAcceptar = new JButton(TDSLanguageUtils.getMessage("mostrar.boton.aceptar"));
		btAcceptar.setBounds(new Rectangle(20,320,100,30));

		btAcceptar.addActionListener( new java.awt.event.ActionListener() {
			public void actionPerformed(ActionEvent e) {
                            dispose();
			}
		} );

		getContentPane().setLayout(null);
		getContentPane().add(pDades,null);
		getContentPane().add(btAcceptar,null);
	        getContentPane().setBackground(Color.WHITE);                
                
		setBounds( new Rectangle(100,100,580,390) );
		setResizable(false);
		setVisible(true);                
	}

        private void LeeRecursos(Integer Bookings) {
                try {
                    listaRecursos = remoto.getRecurso(Bookings);
                    } catch (Exception e) {                
				System.out.println(e.getMessage());
                                  }       
              if (!listaRecursos.isEmpty()) {                
                 for(int i=0;i<listaRecursos.size();i++){
                        ReservaRecurso reservarecurso = listaRecursos.get(i);                                                
                        Integer recurso = reservarecurso.getIdRecurso();
                        Recurso recursos = new Recurso();
                        try {
                            recursos = remoto.consultaRecurso(recurso);
                        } catch (Exception e) {                
				System.out.println(e.getMessage());
                                  }       
                        txt2.setText(recursos.getDescripcion());                        
                        txt3.setText(recursos.getPrecioDia().toString());
                        txt4.setText(recursos.getPrecioHora().toString());
                 }
              }
              else {
                    txt2.setText(TDSLanguageUtils.getMessage("mostrar.mensaje.recursos"));
                    }
        }
        
	/*************************************************************************
	*	M�tode que processa els esdeveniments de la finestra.
	*/
	protected void processWindowEvent(WindowEvent e) {
		if (e.getID()==WindowEvent.WINDOW_CLOSING) {
                        dispose();
		}
		else {
			super.processWindowEvent(e);
		}
	}
        
}